#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://*:8001;http://*:8002;http://*:8003

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Order.MicroService.Api/Order.MicroService.Api.csproj", "Order.MicroService.Api/"]
COPY ["OrderService.Service/Order.MicroService.Service.csproj", "OrderService.Service/"]
COPY ["Order.MicroService.IRepository/Order.MicroService.IRepository.csproj", "Order.MicroService.IRepository/"]
COPY ["Order.MicroService.Models/Order.MicroService.Models.csproj", "Order.MicroService.Models/"]
COPY ["Order.MicroService.ViewModel/Order.MicroService.ViewModel.csproj", "Order.MicroService.ViewModel/"]
COPY ["OrderService.IService/Order.MicroService.IService.csproj", "OrderService.IService/"]
COPY ["CommonHelper/CommonHelper.csproj", "CommonHelper/"]
COPY ["LogInfo/NLogInfo.csproj", "LogInfo/"]
COPY ["Order.MicroService.Repository/Order.MicroService.Repository.csproj", "Order.MicroService.Repository/"]
COPY ["Order.MicroService.Domain/Order.MicroService.Domain.csproj", "Order.MicroService.Domain/"]
#恢复所有的NuGet包
RUN dotnet restore "Order.MicroService.Api/Order.MicroService.Api.csproj"
COPY . .
WORKDIR "/src/Order.MicroService.Api"
#编译
#-c 表示编译配置，这里指定编译配置为Release
#-o 表示编译后文件输出到哪个目录，这里指定编译后输出目录为/app/build
RUN dotnet build "Order.MicroService.Api.csproj" -c Release -o /app/build

FROM build AS publish
#发布
#命令参数与编译的参数基本一致
RUN dotnet publish "Order.MicroService.Api.csproj" -c Release -o /app/publish

FROM base AS final
#设定工作目录，类似命令行中的cd命令，设定之后后续的命令相当于在工作目录中运行
WORKDIR /app
#拷贝其他镜像文件
#使用--from=build表示从build的镜像中拷贝文件，这里的build是引入镜像时指定的别名，
#/app/publish是build镜像的文件路径，最后一个.是指要拷贝到当前镜像来的目录，.表示当前路径，一般也是配合WORKDIR使用
COPY --from=publish /app/publish .

ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
#运行 并指定端口号
#ENTRYPOINT ["dotnet", "Order.MicroService.Api.dll","--urls=http://*:8001"]
#ENTRYPOINT ["dotnet", "Order.MicroService.Api.dll"]
#ENTRYPOINT ["dotnet", "Order.MicroService.Api.dll", "--server.urls", "http://*:8001"]